#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/10/10
# @Author  : Syaoran
# @File    : application_api.py
# @Desc    : 应用接口

from app import app, request
from application.application_manage import ApplicationService
from infrastructure.utils.http import responser
from infrastructure.utils.decorator.oauth2_tool import oauth2_check

# 获取应用列表
@app.route("/api/get_application_list", endpoint="get_application_list", methods=["POST"])
@oauth2_check
def get_application_list():
    res_status, rjson = responser.post_param_check(request, [
        "applicationName", "page", "pageSize"
    ])
    if res_status == "success":
        return ApplicationService.get_application_list(
            applicationName=rjson.get("applicationName"),
            page=int(rjson.get("page", 1)),
            page_size=int(rjson.get("pageSize", 999))
        )
    else:
        return rjson
    

# 更新应用信息
@app.route("/api/update_application", endpoint="update_application", methods=["POST"])
@oauth2_check
def update_application():
    res_status, rjson = responser.post_param_check(request, [
        "id", "applicationName", "status", "description"
    ])
    if res_status == "success":
        return ApplicationService.update_application(
            id=rjson.get("id"),
            application_name=rjson.get("applicationName"),
            status=rjson.get("status"),
            description=rjson.get("description")
        )
    else:
        return rjson
    
# 获取应用详情
@app.route("/api/get_application_info", endpoint="get_application_info", methods=["POST"])
@oauth2_check
def get_application_info():
    res_status, rjson = responser.post_param_check(request, [
        "id"
    ])
    if res_status == "success":
        return ApplicationService.get_application_info(
            id=rjson.get("id")
        )
    else:
        return rjson